package com.itheima.homework.Map接口;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo1 {
    public static void main(String[] args) {
        HashMap<Integer,String> map=new HashMap<>();
        map.put(1,"张三");
        map.put(2,"李四");
        map.put(1,"王五");
        System.out.println(map.size());
        Set<Integer> set = map.keySet();
        for (Integer name : set) {
            String value = map.get(name);
            System.out.println(name+"---"+value);
        }
        System.out.println("--------------------");
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"---"+value);
        }
        System.out.println("--------------------");
        //获取键为1的值，并打印
        Set<Integer> set1 = map.keySet();
        for (Integer integer : set1) {
            if(integer==1){
                System.out.println(map.get(integer));
            }
        }
        if(map.containsKey(10)){
            System.out.println("有");
        }else {
            System.out.println("没有");
        }
        map.remove(1);
        Set<Integer> set2 = map.keySet();
        set2.forEach(s-> System.out.println(s+"---"+map.get(s)));
    }
}
